package controller

import (
	"gitee.com/DonHz/qimi/bluebell/logic"
	"gitee.com/DonHz/qimi/bluebell/models"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)


func PostVoteController(c *gin.Context) {
	var req models.VoteData
	if err:=c.ShouldBindJSON(&req); err!=nil {
		zap.L().Error("bindjson vote param failed", zap.Error(err))
		ResponseError(c, CodeInvalidParam)
		return
	}
	// 获取请求用户的ID
	userIdStr, ok:=c.Get(CtxUserIdKey)
	if !ok {
		zap.L().Error("get user_id from context failed in postVoteController")
		ResponseError(c, CodeNeedLogin)
		return
	}
	userId:=userIdStr.(int64)
	if err:=logic.PostVote(userId, req); err!=nil {
		zap.L().Error("logic.PostVote() failed", zap.Error(err))
		ResponseError(c, CodeServerBusy)
		return
	}
	ResponseSuccess(c, nil)
}
